<!DOCTYPE html>
<html
        layout:decorator="component/mainLayout"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:th="http://www.thymeleaf.org"
        lang="en" xmlns:layout="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" type="text/css" href="/layui/css/layui.css" media="all"/>
    <script src="/layui/layui.js" charset="utf-8"></script>
</head>
<div layout:fragment="contentCenter">
    <!--<div class="mdui-shadow-3  mdui-center mdui-m-t-5  mdui-color-white" style="display: flex;width: 50%">-->
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>新增用户</legend>
    </fieldset>
    <fieldset class="layui-elem-field">
        <legend>用户信息</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="userName" required lay-verify="required" placeholder="请输入姓名"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">手机</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" required lay-verify="required|phone" placeholder="请输入手机"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block" >
                        <input type="password" name="password" required lay-verify="required" placeholder="请输入手机"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item " pane>
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="1" title="男" checked>
                        <input type="radio" name="sex" value="0" title="女" >
                    </div>
                </div>
                <div class="layui-form-item " pane>
                    <label class="layui-form-label">角色</label>
                    <div class="layui-input-block">
                        <input type="radio" name="userRole" value="1" title="管理">
                        <input type="radio" name="userRole" value="0" title="员工" checked>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block" style="float: right">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>
    <style>

    </style>
    <script>

        $(document).ready(function () {
            sliderCollapse.open('#userCollapse');
        })

        layui.use('form', function(){
            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function(data){
                // layer.msg(JSON.stringify(data.field));
                $.ajax({
                    type: "POST",
                    data: data.field,
                    url: "/admin/saveUser",
                    success: function (data) {
                        console.log(data);
                        if (data.status===200){
                            layer.alert("用户新增成功", {icon: 1});
                        }else{
                            mdui.snackbar({
                                message: data.status===200?'登录成功':'登录失败,'+data.message,
                                buttonText: 'OK',
                                timeout:700,
                                onClose: function () {
                                }
                            });
                        }
                    },
                    error: function (request) {
                        mdui.snackbar({
                            message: '登录失败,未知错误',
                            buttonText: 'OK',
                        });
                    }
                });
                return false;
            });
        });
    </script>
</div>
</html>